package com.james.wee.shuangseqiu.dadang;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DaBO {
	public DaBO(String num, int resultsize) {
		this.Nnum = num;
		this.resultsize = resultsize;
	}

	private void sort(List<Map.Entry<String, Integer>> infoIds) {
		Collections.sort(infoIds,
				new Comparator<Map.Entry<String, Integer>>() {
					public int compare(Map.Entry<String, Integer> o1,
							Map.Entry<String, Integer> o2) {
						return (o2.getValue() - o1.getValue());
					}
				});

	}

	private int resultsize;
	private String Nnum = "";
	private int n_1_index = 0;
	private int n_2_index = 0;
	private int n_3_index = 0;
	private int n_4_index = 0;
	private int n_5_index = 0;
	private int n_6_index = 0;
	private int n_7_index = 0;
	private int n_8_index = 0;
	private int n_9_index = 0;
	private int n_10_index = 0;
	private int n_11_index = 0;
	private int n_12_index = 0;
	private int n_13_index = 0;
	private int n_14_index = 0;
	private int n_15_index = 0;
	private int n_16_index = 0;
	private int n_17_index = 0;
	private int n_18_index = 0;
	private int n_19_index = 0;
	private int n_20_index = 0;
	private int n_21_index = 0;
	private int n_22_index = 0;
	private int n_23_index = 0;
	private int n_24_index = 0;
	private int n_25_index = 0;
	private int n_26_index = 0;
	private int n_27_index = 0;
	private int n_28_index = 0;
	private int n_29_index = 0;
	private int n_30_index = 0;
	private int n_31_index = 0;
	private int n_32_index = 0;
	private int n_33_index = 0;

	public void add(String number) {
		switch (Integer.parseInt(number)) {
		case 1:
			n_1_index++;
			break;
		case 2:
			n_2_index++;
			break;
		case 3:
			n_3_index++;
			break;
		case 4:
			n_4_index++;
			break;
		case 5:
			n_5_index++;
			break;
		case 6:
			n_6_index++;
			break;
		case 7:
			n_7_index++;
			break;
		case 8:
			n_8_index++;
			break;
		case 9:
			n_9_index++;
			break;
		case 10:
			n_10_index++;
			break;
		case 11:
			n_11_index++;
			break;
		case 12:
			n_12_index++;
			break;
		case 13:
			n_13_index++;
			break;
		case 14:
			n_14_index++;
			break;
		case 15:
			n_15_index++;
			break;
		case 16:
			n_16_index++;
			break;
		case 17:
			n_17_index++;
			break;
		case 18:
			n_18_index++;
			break;
		case 19:
			n_19_index++;
			break;
		case 20:
			n_20_index++;
			break;
		case 21:
			n_21_index++;
			break;
		case 22:
			n_22_index++;
			break;
		case 23:
			n_23_index++;
			break;
		case 24:
			n_24_index++;
			break;
		case 25:
			n_25_index++;
			break;
		case 26:
			n_26_index++;
			break;
		case 27:
			n_27_index++;
			break;
		case 28:
			n_28_index++;
			break;
		case 29:
			n_29_index++;
			break;
		case 30:
			n_30_index++;
			break;
		case 31:
			n_31_index++;
			break;
		case 32:
			n_32_index++;
			break;
		case 33:
			n_33_index++;
			break;

		}
	}

	@Override
	public String toString() {
		String restr = "\n" + Nnum + ":共" + resultsize + "次";
		Method m = null;
		Integer itmp = 0;
		Map<String, Integer> tmp = new HashMap<String, Integer>();
		for (int i = 1; i < 34; i++) {
			try {
				m = DaBO.class.getDeclaredMethod("getN_" + i + "_index", null);
				itmp = (Integer) m.invoke(this, null);
				if(i<10)
				tmp.put("0"+i, itmp);
				else
					tmp.put(""+i, itmp);	
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(
				tmp.entrySet());
		sort(infoIds);
		for(int i=0,len=infoIds.size();i<len;i++){
			restr+="\n"+infoIds.get(i).toString().replace("=", ",");
		}
//		if (i < 10)
//			restr += "\n 0" + i + "," + itmp;
//		else
//			restr += "\n " + i + "," + itmp;
		return restr;
	}

	public int getResultsize() {
		return resultsize;
	}

	public void setResultsize(int resultsize) {
		this.resultsize = resultsize;
	}

	public int getN_1_index() {
		return n_1_index;
	}

	public void setN_1_index(int n_1_index) {
		this.n_1_index = n_1_index;
	}

	public int getN_2_index() {
		return n_2_index;
	}

	public void setN_2_index(int n_2_index) {
		this.n_2_index = n_2_index;
	}

	public int getN_3_index() {
		return n_3_index;
	}

	public void setN_3_index(int n_3_index) {
		this.n_3_index = n_3_index;
	}

	public int getN_4_index() {
		return n_4_index;
	}

	public void setN_4_index(int n_4_index) {
		this.n_4_index = n_4_index;
	}

	public int getN_5_index() {
		return n_5_index;
	}

	public void setN_5_index(int n_5_index) {
		this.n_5_index = n_5_index;
	}

	public int getN_6_index() {
		return n_6_index;
	}

	public void setN_6_index(int n_6_index) {
		this.n_6_index = n_6_index;
	}

	public int getN_7_index() {
		return n_7_index;
	}

	public void setN_7_index(int n_7_index) {
		this.n_7_index = n_7_index;
	}

	public int getN_8_index() {
		return n_8_index;
	}

	public void setN_8_index(int n_8_index) {
		this.n_8_index = n_8_index;
	}

	public int getN_9_index() {
		return n_9_index;
	}

	public void setN_9_index(int n_9_index) {
		this.n_9_index = n_9_index;
	}

	public int getN_10_index() {
		return n_10_index;
	}

	public void setN_10_index(int n_10_index) {
		this.n_10_index = n_10_index;
	}

	public int getN_11_index() {
		return n_11_index;
	}

	public void setN_11_index(int n_11_index) {
		this.n_11_index = n_11_index;
	}

	public int getN_12_index() {
		return n_12_index;
	}

	public void setN_12_index(int n_12_index) {
		this.n_12_index = n_12_index;
	}

	public int getN_13_index() {
		return n_13_index;
	}

	public void setN_13_index(int n_13_index) {
		this.n_13_index = n_13_index;
	}

	public int getN_14_index() {
		return n_14_index;
	}

	public void setN_14_index(int n_14_index) {
		this.n_14_index = n_14_index;
	}

	public int getN_15_index() {
		return n_15_index;
	}

	public void setN_15_index(int n_15_index) {
		this.n_15_index = n_15_index;
	}

	public int getN_16_index() {
		return n_16_index;
	}

	public void setN_16_index(int n_16_index) {
		this.n_16_index = n_16_index;
	}

	public int getN_17_index() {
		return n_17_index;
	}

	public void setN_17_index(int n_17_index) {
		this.n_17_index = n_17_index;
	}

	public int getN_18_index() {
		return n_18_index;
	}

	public void setN_18_index(int n_18_index) {
		this.n_18_index = n_18_index;
	}

	public int getN_19_index() {
		return n_19_index;
	}

	public void setN_19_index(int n_19_index) {
		this.n_19_index = n_19_index;
	}

	public int getN_20_index() {
		return n_20_index;
	}

	public void setN_20_index(int n_20_index) {
		this.n_20_index = n_20_index;
	}

	public int getN_21_index() {
		return n_21_index;
	}

	public void setN_21_index(int n_21_index) {
		this.n_21_index = n_21_index;
	}

	public int getN_22_index() {
		return n_22_index;
	}

	public void setN_22_index(int n_22_index) {
		this.n_22_index = n_22_index;
	}

	public int getN_23_index() {
		return n_23_index;
	}

	public void setN_23_index(int n_23_index) {
		this.n_23_index = n_23_index;
	}

	public int getN_24_index() {
		return n_24_index;
	}

	public void setN_24_index(int n_24_index) {
		this.n_24_index = n_24_index;
	}

	public int getN_25_index() {
		return n_25_index;
	}

	public void setN_25_index(int n_25_index) {
		this.n_25_index = n_25_index;
	}

	public int getN_26_index() {
		return n_26_index;
	}

	public void setN_26_index(int n_26_index) {
		this.n_26_index = n_26_index;
	}

	public int getN_27_index() {
		return n_27_index;
	}

	public void setN_27_index(int n_27_index) {
		this.n_27_index = n_27_index;
	}

	public int getN_28_index() {
		return n_28_index;
	}

	public void setN_28_index(int n_28_index) {
		this.n_28_index = n_28_index;
	}

	public int getN_29_index() {
		return n_29_index;
	}

	public void setN_29_index(int n_29_index) {
		this.n_29_index = n_29_index;
	}

	public int getN_30_index() {
		return n_30_index;
	}

	public void setN_30_index(int n_30_index) {
		this.n_30_index = n_30_index;
	}

	public int getN_31_index() {
		return n_31_index;
	}

	public void setN_31_index(int n_31_index) {
		this.n_31_index = n_31_index;
	}

	public int getN_32_index() {
		return n_32_index;
	}

	public void setN_32_index(int n_32_index) {
		this.n_32_index = n_32_index;
	}

	public int getN_33_index() {
		return n_33_index;
	}

	public void setN_33_index(int n_33_index) {
		this.n_33_index = n_33_index;
	}

	public String getNnum() {
		return Nnum;
	}

	public void setNnum(String nnum) {
		Nnum = nnum;
	}

}
